package cn.itcast.crm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.crm.dao.CustomerDao;
import cn.itcast.crm.domain.Customer;

@Service
@Transactional(readOnly=false)
public class CustomerServiceImpl implements CustomerService {
	@Autowired
	private CustomerDao customerdao;
	@Override
	public List<Customer> getCustomerNotunAssociate(Boolean b) {
		// TODO Auto-generated method stub
		System.out.println("---------------又走错了啊-------------------");
		return customerdao.findByFixedAreaIdIsNull();
	}

	@Override
	public List<Customer> getCustomerByFixedId(String fid) {
		// TODO Auto-generated method stub
		System.out.println("---------------走错了啊-------------------");
		return customerdao.findByFixedAreaId(fid);
	}

	@Override
	public void associate(List<Integer> cids, String fid) {
		// TODO Auto-generated method stub
		customerdao.unblindByFixedId(fid);
		if(cids.size()==0){
			return;
		}else{
			customerdao.associate(cids, fid);
		}
	}

	@Override
	public Customer saveCustomer(Customer customer) {
		// TODO Auto-generated method stub
		System.out.println(customer);
		customerdao.save(customer);
		return null;
	}

	@Override
	public Customer getbyTelephone(String telephone) {
		// TODO Auto-generated method stub
		return customerdao.getByTelephone(telephone);
	}

	@Override
	public void updateCustomer(String telephone) {
		// TODO Auto-generated method stub
		customerdao.updateCustomer(telephone);
	}

	@Override
	public Customer findByTelephoneAndPassword(String telephone,
			String password) {
		// TODO Auto-generated method stub
		Customer customer=customerdao. findByTelephoneAndPassword( telephone,password);
		System.out.println("------------------------"+customer+"-----------------------");
		return customer;
	}

	@Override
	public Customer findById(Integer id) {
		// TODO Auto-generated method stub
		Customer customer=customerdao.findOne(id);
		System.out.println(customer);
		return customer;
	}

	

}
